package net.pm.common.toolkit;

import java.util.ArrayList;
import java.util.List;

/**分页工具类
 * @param <T>
 */
@SuppressWarnings("unused")
public final class Pager<T> {

	/**当前页码
	 */
	private Integer pageno = DevConstant.PAGE_DEFAULT_NO;
	/** 当前页宽
	 */
	private Integer pagesize = DevConstant.PAGE_DEFAULT_SIZE;
	/**总页数
	 */
	private Integer pagecount;
	/**总记录数
	 */
	private Long totalsize;
	/**结果集
	 */
	private List<T> result;
	/**是否有下一页
	 */
	private Boolean hasPre;
	
	/**
	 * 上一页
	 */
	private Integer prePage;
	
	/**是否有上一页
	 */
	private Boolean hasNext;
	
	/**
	 * 下一页
	 */
	private Integer nextPage;
	
	/**
	 * 首页
	 */
	private Integer homePage;
	
	/**
	 * 尾页
	 */
	private Integer endPage;

	/**获取当前页码的前后X个页码的数字集合,
	 * @return
	 */
	public List<Integer> getPageNumberList() {
		List<Integer> xlist = new ArrayList<Integer>();
		// 当前页的前x页
		int diff = this.pageno - DevConstant.PAGE_DEFAULT_X;
		int begin = diff > 0 ? diff : 1;
		diff = 0;
		// 当前页的后x页
		diff = this.pageno + DevConstant.PAGE_DEFAULT_X;
		int end = diff <= this.pagecount ? diff : this.pagecount;
		for (; begin <= end; begin++) {
			xlist.add(begin);
		}
		return xlist;
	}
	
	public Pager() {
		super();
	}

	public Pager(Integer pageno, Integer pagesize, Integer pagecount,
			long totalsize, List<T> result) {
		super();
		this.pageno = pageno;
		this.pagesize = pagesize;
		this.pagecount = pagecount;
		this.totalsize = totalsize;
		this.result = result;
	}

	public Integer getPageno() {
		return pageno;
	}

	public void setPageno(Integer pageno) {
		this.pageno = pageno;
	}

	public Integer getPagesize() {
		return pagesize;
	}

	public void setPagesize(Integer pagesize) {
		this.pagesize = pagesize;
	}

	public Integer getPagecount() {
		return pagecount;
	}

	public void setPagecount(Integer pagecount) {
		this.pagecount = pagecount;
	}

	public Long getTotalsize() {
		return totalsize;
	}

	public void setTotalsize(long totalsize) {
		this.totalsize = totalsize;
	}

	public List<T> getResult() {
		return result;
	}

	public void setResult(List<T> result) {
		this.result = result;
	}

	public Boolean getHasPre() {
		return this.pageno > 1;
	}

	public Boolean getHasNext() {
		return this.pageno < this.pagecount;
	}

	public Integer getPrePage() {
		return this.pageno - 1;
	}

	public Integer getNextPage() {
		return this.pageno + 1;
	}

	public Integer getHomePage() {
		return 1;
	}

	public Integer getEndPage() {
		return pagecount;
	}
	
	
	
}
